package com.jk.dmconsumer.controller;

import com.jk.dmcommon.LybEntity.UserEntity;
import com.jk.dmconsumer.service.UserService;
import com.jk.dmconsumer.util.MD5Utils;
import com.jk.dmconsumer.util.RSAUtils;
import com.jk.dmconsumer.utils.HttpClientUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;

@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    UserService userService;


    /**
     * @description:  新增注册用户
     * @param: [userEntity]
     * @return: void
     * @author 刘杨彬
     * @date: 2021/9/6 15:46
     */
    @RequestMapping("registeredUsers")
    public void registeredUsers(UserEntity userEntity){

        userService.registeredUsers(userEntity);
    }






    /**
     * @description:  请求验证码
     * @param: [request, useriPhone]
     * @return: void
     * @author 刘杨彬
     * @date: 2021/9/6 19:58
     */
    @RequestMapping("gain")
    public void gain(HttpServletRequest request, String useriPhone){
        String args="";
        request.getSession().setAttribute("useriPhone", useriPhone);
        HttpClientUtil.Yzm(args, request);
    }


    /**
     * @description:  请求注册
     * @param: [user, request]
     * @return: java.lang.Object
     * @author 刘杨彬
     * @date: 2021/9/7 10:55
     */

    @RequestMapping("login1")
    public String login1(UserEntity user){
        String code = MD5Utils.code(user.getUserPwd());
        user.setUserPwd(code);
        return userService.login1(user);
    }


    /**
     * @description:  前台用户登录
     * @param: [user]
     * @return: java.lang.String
     * @author 刘杨彬
     * @date: 2021/9/7 19:27
     */
    @RequestMapping("frontDeskLogin")
    public String userLogin(UserEntity user){
        String code = MD5Utils.code(user.getUserPwd());
        user.setUserPwd(code);
        return userService.userLogin(user);
    }
    @RequestMapping("getSession")
    public Object getSession(HttpServletRequest request){
        UserEntity user  = (UserEntity) request.getSession().getAttribute("user");
        return user;
    }














}
